#coding=utf-8

import random
import time
from tkinter import *


root=Tk()
root.title('2201点名系统')
root.iconbitmap(bitmap="favicon.ico")
title=Label(root,text=' 欢迎使用2201班随机点名系统2.0！',font=("宋体",25),bg='white')
title.pack()
root.config(bg='white')
def chushihua():
    global names
    names=['卫新宇','王尚熙','宁  钰','黄天龙','张奥玮','刘思如','王京晶','林怡彤','时培杰','杨柳炜','袁紫涵','张卓琳','孙艺丹','郭泽坤','樊思晨','马梓航','崔梦垚','林钲皓','高梓萌','李嘉图','靳昊润','张巧巧','董晓泰','商妍茹','毕昭阳','胡川琪','张颢译','景元瑞','柴嘉晨','梁靖怡','许薰元','郭亚鑫','程相杰','尤常凯','王浩宇','马佳敏','李金阳','宋文晖','李季泽','弓士森','杨子轩','上官佐','胡梦涛','宁一张','宁一弛','张宸坤']
chushihua()
name=StringVar()
name.set('      ')

num=0
key=0
t=0

def startname():
        global i
        global name
        global names
        global t
        global selectlist
        i=1
        start_time = time.time()
        starttime = time.time()
        namedel()
        if num==47:
              names.append('吕承玺')
        while i<=num:
            time.sleep(0.075)
            name.set(random.choice(names))
            end_time = time.time()
            endtime = time.time()
            if end_time-start_time>random.uniform(0,3) and endtime-starttime>1.5:
                selectlist.config(state=NORMAL)
                if t!=0:
                    selectlist.insert(END,'，')
                selectlist.insert(END, name.get())
                names.remove(name.get())
                t+=1
                selectlist.config(state=DISABLED)
                i+=1
                start_time = time.time()
            root.update()

def namedel():
        global selectlist
        global t
        global names
        global suiji
        global key
        root.after_cancel
        chushihua()
        selectlist.config(state=NORMAL)
        t=0
        selectlist.delete(0.1,END)
        selectlist.config(state=DISABLED)

def gettime():
      timestr = time.strftime("%H:%M:%S")
      lb.configure(text=timestr)
      root.after(1000,gettime)

def numplus():
        global num
        global geshu
        if num<47:
            num+=1
            geshu.destroy()
            geshu=Label(anniu,text=num,font=("宋体",20,'bold'),width=5,bg='white')
            geshu.pack(side=LEFT)

def numminus():
        global num
        global geshu
        global jian
        global jia
        if num>0:
            num-=1
            geshu.destroy()
            geshu=Label(anniu,text=num,font=("宋体",20,'bold'),width=5,bg='white')
            geshu.pack(side=LEFT)


mingzi=Frame(root,bg='white')
suiji=Label(mingzi,textvariable=name,font=("宋体",30,'bold'),relief=FLAT,bg='white')
suiji.pack(side=LEFT,padx=150,pady=20)
selectlist=Text(mingzi,font=("宋体",20,'bold'),relief=FLAT,width=24, height=5,state=DISABLED,bg='white')
selectlist.pack(side=RIGHT)
scrollbar=Scrollbar(mingzi,command=selectlist.yview,bg='white')
scrollbar.pack(side=RIGHT, fill=Y,before=selectlist)
selectlist.config(yscrollcommand=scrollbar.set)
mingzi.pack(pady=20)


anniu=Frame(root,bg='white')
renshu=Label(anniu,text='人数:',font=("宋体",20,'bold'),bg='white')
renshu.pack(side=LEFT,padx=50)
jian=Button(anniu,text='-',relief=FLAT,font=("宋体",20,'bold'),bg='white',command=numminus)
jian.pack(side=LEFT)
geshu=Label(anniu,text=num,font=("宋体",20,'bold'),width=5,bg='white')
geshu.pack(side=LEFT)
jia=Button(anniu,text='+',relief=FLAT,font=("宋体",20,'bold'),bg='white',command=numplus)
jia.pack(side=RIGHT)
start=Button(anniu,text='开始',relief=FLAT,font=("宋体",20,'bold'),bg='white',command=startname)
start.pack(side=RIGHT,padx=50,before=jia)
anniu.pack()


lb = Label(root,text='',font=("宋体",15),bg='white')
lb.pack(side=LEFT)
gettime()


shuiyin=Label(root,text='——Made by lv',font=("宋体",15),bg='white')
shuiyin.pack(side=RIGHT)


root.mainloop()